import db from './db'
import { mock } from 'mockjs'
import { orderBy } from '@/utils'

// GET 轮播列表
mock('carousel/list', 'get', () => {
  return {
    err: 0,
    desc: '执行成功！',
    result: orderBy( db.select('gx_carousel') )
  }
})

// POST 轮播状态
mock('carousel/state', 'post', ( payload ) => {
  const { id, state } = JSON.parse(payload.body)
  return {
    err: 0,
    desc: '执行成功！',
    result: db.put ('gx_carousel', id, { state })
  }
})

// POST 轮播删除
mock('carousel/remove', 'post', ( payload ) => {
  const { ids } = JSON.parse(payload.body);
  return {
    err: 0,
    desc: '执行成功！',
    result: db.delete ('gx_carousel', ids)
  }
})

// POST 轮播新增
mock('carousel/add', 'post', ( payload ) => {
  const form = JSON.parse(payload.body)
  return {
    err: 0,
    desc: '执行成功！',
    result: db.add ('gx_carousel', form)
  }
})

// POST 轮播修改
mock('carousel/edit', 'post', ( payload ) => {
  const {id, ...others} = JSON.parse(payload.body)
  return {
    err: 0,
    desc: '执行成功！',
    result: db.put('gx_carousel', id, others)
  }
})